//
//  KYAppConfigModel.m
//  KYKJPackDemo
//
//  Created by 罗新 on 2017/11/8.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "KYAppConfigModel.h"
#import <objc/runtime.h>
@implementation KYAppConfigModel
+ (instancetype)refreshAppConfigDataWithDict:(NSDictionary *)dict{
    KYAppConfigModel *model = [[KYAppConfigModel alloc] init];
    model.shareModel = [KYShareValueModel refreshShareValueWithDict:dict[@"share_value"]];
    model.readModel = [KYReaderValueModel refreshReaderValueWithDict:dict[@"reader_value"]];
    model.systemModel = [KYSystemValueModel refreshSystemValueWithDict:dict[@"system_value"]];
    model.appFunctionModel = [KYAppFunctionModel refreshAppFunctionWithDict:dict[@"app_function"]];
    model.configModel = [KYConfigModel refreshConfigWithDict:dict[@"config"]];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}
@end

@implementation KYShareValueModel
+ (instancetype)refreshShareValueWithDict:(NSDictionary *)dict{
    KYShareValueModel *model = [[KYShareValueModel alloc] init];
    model.share_type = dict[@"share_type"];
    model.share_wxappid = dict[@"share_wxappid"];
    model.share_wxSecret = dict[@"share_wxSecret"];
    model.share_qqppid = dict[@"share_qqppid"];
    model.share_qqKey = dict[@"share_qqKey"];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}

@end

@implementation KYReaderValueModel;
+ (instancetype)refreshReaderValueWithDict:(NSDictionary *)dict{
    KYReaderValueModel *model = [[KYReaderValueModel alloc] init];
    model.reader_qq = dict[@"reader_qq"];
    model.reader_email = dict[@"reader_email"];
    model.reader_title = dict[@"reader_title"];
    model.reader_content = dict[@"reader_content"];
    model.reader_previous = dict[@"reader_previous"];
    model.reader_next = dict[@"reader_next"];
    model.reader_advplace = dict[@"reader_advplace"];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}

@end

@implementation KYSystemValueModel;
+ (instancetype)refreshSystemValueWithDict:(NSDictionary *)dict{
    KYSystemValueModel *model = [[KYSystemValueModel alloc] init];
    model.app_website = dict[@"app_website"];
    model.app_text = dict[@"app_text"];
    model.app_ads = dict[@"app_ads"];
    model.app_type = dict[@"app_type"];
    model.interval_time = dict[@"interval_time"];
    model.color = dict[@"color"];
    model.history = dict[@"history"];
    model.ios_tabbar = dict[@"ios_tabbar"];
    model.jpush_appkey = dict[@"jpush_appkey"];
    model.token = dict[@"token"];
    model.menuBgImg = dict[@"menuBgImg"];
    NSMutableArray *menuArrM = [NSMutableArray array];
    for (NSDictionary *menuDic in dict[@"menu"]) {
        KYSideMenuModel *model = [KYSideMenuModel refreshSideMenuWithDict:menuDic];
        [menuArrM addObject:model];
    }
    model.menu = [menuArrM copy];
    model.sideSlipStatu = dict[@"sideSlipStatu"];
    model.appStatus = dict[@"appStatus"];
    model.appMsg = dict[@"appMsg"];
    model.canClean = dict[@"canClean"];
    model.isVideoFast = dict[@"isVideoFast"];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}

@end

@implementation KYSideMenuModel;
+ (instancetype)refreshSideMenuWithDict:(NSDictionary *)dict{
    KYSideMenuModel *model = [[KYSideMenuModel alloc] init];
    model.menuTitle = dict[@"menuTitle"];
    model.menuUrl = dict[@"menuUrl"];
    model.menuImg = dict[@"menuImg"];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}
@end

@implementation KYAppFunctionModel;
+ (instancetype)refreshAppFunctionWithDict:(NSDictionary *)dict{
    KYAppFunctionModel *model = [[KYAppFunctionModel alloc] init];
    model.open = dict[@"open"];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}

@end

@implementation KYConfigModel;
+ (instancetype)refreshConfigWithDict:(NSDictionary *)dict{
    KYConfigModel *model = [[KYConfigModel alloc] init];
    model.qrcode_set = dict[@"qrcode_set"];
    model.qrcode_id = dict[@"qrcode_id"];
    return model;
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
    unsigned int count = 0;
    Ivar* ivars = class_copyIvarList([self class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char* name = ivar_getName(ivar);
        NSString* key = [NSString stringWithUTF8String:name];
        [aCoder encodeObject:[self valueForKey:key] forKey :key];
    }
    free(ivars);
}
- (id)initWithCoder:(NSCoder*)aDecoder {
    if (self == [super init]) {
        unsigned int count = 0;
        Ivar* ivars = class_copyIvarList([self class], &count);
        for (int i = 0; i < count; i++) {
            Ivar ivar = ivars[i];
            const char* name = ivar_getName(ivar);
            NSString* key = [NSString stringWithUTF8String:name];
            id value =  [aDecoder decodeObjectForKey:key];
            [self setValue:value forKey:key];
        }
        free(ivars);
    }
    return self;
}
@end
